package com.demo.delivery.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.core.content.ContextCompat;

import com.demo.delivery.R;

public class HomeTitleAdapter extends BaseAdapter {

    private final static int[] images = {
            R.drawable.ic_home_title_knife_fork,
            R.drawable.ic_home_title_homestay,
            R.drawable.ic_home_title_medical_box,
            R.drawable.ic_home_title_degree_hat,
            R.drawable.ic_home_title_apple_one,
            R.drawable.ic_home_title_baby_feet,
            R.drawable.ic_home_title_frog,
            R.drawable.ic_home_title_entertainment
    };
    private final static String[] names = {"美食", "酒店/民宿", "买药", "学习", "免费领水果", "按摩/足疗", "蛙小侠", "休闲/玩乐"};

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public String getItem(int i) {
        return names[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {
        if (convertView == null) {
            Context context = viewGroup.getContext();
            LayoutInflater layoutInflater = ContextCompat.getSystemService(context, LayoutInflater.class);
            convertView = layoutInflater.inflate(R.layout.item_home_title, null);
        }
        ImageView imageView = convertView.findViewById(R.id.iv);
        TextView textView = convertView.findViewById(R.id.tv);
        imageView.setImageResource(images[i]);
        textView.setText(names[i]);
        return convertView;
    }
}
